import Vue from 'vue'

import Cookies from 'js-cookie'

import 'normalize.css/normalize.css' // a modern alternative to CSS resets

import Element from 'element-ui'
import { Message } from 'element-ui'
import './styles/element-variables.scss'

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'
//import VueRouter from 'vue-router'
import i18n from './lang' // internationalization
import './icons' // icon
import './icons/5s/iconfont.css'
import './permission' // permission control
import './utils/error-log' // error log

import * as filters from './filters' // global filters
import constant from './global' //gloabl constant 
import HlSearchTablePagination from 'h-table-list'
import VueCoreVideoPlayer from 'vue-core-video-player'
// 防抖处理-立即执行
const on = Vue.prototype.$on
Vue.prototype.$on = function(event, func) {
    let timer;
    let flag = true;
    let newFunc = func
    if (event == 'click' || event == 'dbClick') {
        newFunc = function() {
            if (flag) {
                func.apply(this, arguments)
                flag = false

            } else {
                Message({
                    message: "请不要重复操作",
                    type: "error",
                    duration: 2 * 1000
                })

            }
            clearTimeout(timer)
            timer = setTimeout(function() {
                flag = true
            }, 2000)
        }
    }
    on.call(this, event, newFunc)
}

Vue.use(VueCoreVideoPlayer)
    /**
     * If you don't want to use mock-server
     * you want to use mockjs for request interception
     * you can execute:
     *
     * import { mockXHR } from '../mock'
     * mockXHR()
     */

Vue.use(Element, {
    size: Cookies.get('size') || 'medium', // set element-ui default size
    i18n: (key, value) => i18n.t(key, value)
})
Vue.use(constant);
// register global utility filters
Object.keys(filters).forEach(key => {
    Vue.filter(key, filters[key])
})

Vue.config.productionTip = false
Vue.use(HlSearchTablePagination)
new Vue({
    el: '#app',
    router,
    store,
    i18n,
    render: h => h(App)
})



// let router1 = null;
// let instance = null;

// function render(props = {}) {
//     const { container } = props;
//     router1 = new VueRouter({
//         base: window.__POWERED_BY_QIANKUN__ ? '/vue' : '/',
//         mode: 'history',
//         router,
//     });

//     instance = new Vue({
//         router1,
//         store,
//         render: h => h(App),
//     }).$mount(container ? container.querySelector('#app') : '#app');
// }

// if (!window.__POWERED_BY_QIANKUN__) {
//     render();
// }

// function storeTest(props) {
//     props.onGlobalStateChange &&
//         props.onGlobalStateChange(
//             (value, prev) => console.log(`[onGlobalStateChange - ${props.name}]:`, value, prev),
//             true,
//         );
//     props.setGlobalState &&
//         props.setGlobalState({
//             ignore: props.name,
//             user: {
//                 name: props.name,
//             },
//         });
// }
// export async function bootstrap() {
//     console.log('[vue] vue app bootstraped');
// }

// export async function mount(props) {
//     console.log('[vue] props from main framework', props);
//     storeTest(props);
//     render(props);
// }

// export async function unmount() {
//     instance.$destroy();
//     instance.$el.innerHTML = '';
//     instance = null;
//     router1 = null;
// }